﻿using Castle.DynamicProxy;
using commonFramwork.Log;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace commonFramwork.Interceptor
{
    /// <summary>
    /// 
    /// </summary>
    public class CallLogger : IInterceptor
    {

        private static MyuLogger loger = new MyuLogger(typeof(CallLogger));

        public void Intercept(IInvocation invocation)
        {
            loger.Info($"你正在调用方法 \"{invocation.Method.Name}\"  参数是 {string.Join(", ", invocation.Arguments.Select(a => (a ?? "").ToString()).ToArray())}... ");
            //在被拦截的方法执行完毕后 继续执行
             invocation.Proceed();

            loger.Info($"方法执行完毕，返回结果：{invocation.ReturnValue}");
        }
    }
}
